#pragma once

#include "HashTable.hpp"

namespace YX
{
	template<class K,class V,class Hash=HashFunc<K>>
	class UnorderedMap
	{
	private:

		struct MapKeyOfType
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}

		};

		HashTable<K, pair<K, V>, Hash, MapKeyOfType> _hashTable;

	public:

		typedef typename HashTable<K, pair<K, V>, Hash, MapKeyOfType>::iterator iterator;

		pair<iterator, bool> Insert(const pair<K, V>& kv)
		{
			return _hashTable.Insert(kv);
		}

		iterator begin()
		{
			return _hashTable.begin();
		}

		iterator end()
		{
			return _hashTable.end();
		}

		bool Erase(const K& key)
		{
			return _hashTable.Erase(key);
		}

		iterator Find(const K& key)
		{
			return _hashTable.Find(key);
		}

		V& operator[](const K& key)
		{
			return (_hashTable.Insert(make_pair(key, V())).first)->second;
		}


	};

}